---
description: Codegen for Hasura Actions
keywords:
  - hasura
  - docs
  - actions
  - codegen
slug: index
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Thumbnail from '@site/src/components/Thumbnail';

# Actions Codegen

## Introduction

Actions need HTTP handlers to run the business logic. It might be inconvenient to write the complete handler code for
every action. Luckily, GraphQL's type system allows us to auto-generate the boilerplate code for actions.

:::info Note

Hasura currently has codegen set up for a few frameworks. The list of supported frameworks should grow with
contributions from the community.

:::

## Generating handler code for your action {#actions-codegen-execute}

<Tabs groupId="user-preference" className="api-tabs">
<TabItem value="console" label="Console">

Head to the `Actions -> [action-name] -> Codegen` tab in the Console

You can select the framework of your choice to get the corresponding handler boilerplate code.

<Thumbnail src="/img/actions/console-codegen-tab.png" alt="Console codegen tab" />

</TabItem>
<TabItem value="cli" label="CLI">

**Configuration**

Before being able to codegen for actions, you have to configure your CLI.

Run:

```bash
hasura actions use-codegen
```

1.  Choose which framework you want to codegen for:

    <Thumbnail src="/img/actions/cli-framework-prompt.png" alt="CLI Framework Prompt" />

2.  Choose if you also wish to clone a starter kit for the chosen framework:

    <Thumbnail src="/img/actions/cli-starter-kit-prompt.png" alt="CLI Starter Kit Prompt" />

3.  Choose a path where you want to output the auto-generated code files
    <Thumbnail src="/img/actions/cli-output-dir-prompt.png" alt="CLI Starter Kit Prompt" />

This command will update your `config.yaml` with the codegen config as per your preferences. You can also set these
values manually in `config.yaml`.

For example:

```yaml {8-10}
version: '2'
endpoint: http://localhost:8080
metadata_directory: metadata
migrations_directory: migrations
actions:
  handler_webhook_baseurl: http://localhost:3000
  kind: synchronous
  codegen:
    framework: nodejs-express
    output_dir: ./nodejs-express/src/handlers/
```

**Codegen**

To finally get auto-generated code for an action, run:

```bash
hasura actions codegen <action-name>
```

The codegen files will be generated at the `output_dir` path from `config.yaml`.

</TabItem>
</Tabs>

## Codegen for your framework

As of now, Hasura provides codegen for a few frameworks (`nodejs-express`, `typescript-zeit`, `python-flask` and many
more). You can see the full list in the `Codegen` tab on the Console after you've
[created an action](/actions/create.mdx).

We will continue adding more examples to the documentation.

- [Python & Flask](/actions/codegen/python-flask.mdx)

### Building your own codegen

If you wish to build a code generator for your framework
[read the contrib guide](https://github.com/hasura/codegen-assets/blob/master/builder-kit/README.md).

:::info Additional Resources

Introduction to Hasura Actions -
[View Recording](https://hasura.io/events/webinar/hasura-actions/?pg=docs&plcmt=body&cta=view-recording&tech=).

:::
